﻿using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Linq;
using System.Text;

namespace Utilities.ArrayLib
{
    public class ArrayLib
    {
        /// <summary>
        /// Seed, uses current date time, in random class.
        /// </summary>
        private static int seed = DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond;

        /// <summary>
        /// Get k random elements of a list
        /// </summary>
        /// <typeparam name="T">Type of object in this list</typeparam>
        /// <param name="NumOfElements">The number of elements needed to get</param>
        /// <param name="OriginalList">The original list of elements</param>
        /// <returns>The list of randomed retrieved elements</returns>
        public static List<T> GetRandomElements<T>(int NumOfElements, List<T> OriginalList)
        {
            List<T> ResultList = new List<T>();
            List<T> tempList = new List<T>(OriginalList);

            if (NumOfElements > OriginalList.Count)
            {
                return ResultList;
            }

            Random random;
            
            while (ResultList.Count < NumOfElements)
            {
                random = new Random(seed++);
                int index = random.Next(0, tempList.Count);
                ResultList.Add(tempList.ElementAt(index));
                tempList.RemoveAt(index);
            }

            return ResultList;
        }
    }
}
